<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{#  if(d.news_state == '审核中'){}}
            <span>审核中</span>
            {{#}}}
            {{#  if(d.news_state=='审核通过' || d.news_state=='审核未通过'){}}
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-add" lay-event="delite">查看历史批注</a>
            {{#}}}
        </script>

    </div>
</div>
<div id="showView" style="display: none">
<div  style="text-align: center;font-size: 20px;padding-top: 5px">批注列表</div>
<div>
    <table class="layui-table">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="200">
        </colgroup>
        <thead>
        <tr>
            <th>批注时间</th>
            <th>批注人</th>
            <th>批注信息</th>
        </tr>
        </thead>
        <tbody id="tbody">

        </tbody>

    </table>
</div>
</div>

<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/news/news_list',
            toolbar: '#toolbarDemo',
            cols: [[
                {field: 'id', width: 80, title: '编号', sort: true,templet:'#zizeng',align:'center',templet:function (d) {
                        return d.LAY_TABLE_INDEX+1;
                    }},
                {field: 'news_name', width: 180, title: '新闻名称',align:'center'},
                {field: 'news_content', width: 180, title: '新闻内容', sort: true,align:'center'},
                {field: 'news_state', width: 180, title: '审核状态',align:'center'},
                {field: 'createTime', width: 180, title: '创建时间',align:'center',templet :function(d) {
                    return showTime(d.createTime)
                }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page:true,
            skin: 'line',
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            switch(obj.event){
                case 'add':
                    var index = layer.open({
                        title: '添加新闻申请',
                        type: 2,
                        area: ['500px', '600px'],
                        content: '../page/table/news_add.html',
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    break;
            }
        });


        /**
         * 行工具事件
         */
        table.on('tool(currentTableFilter)', function (obj) {
            switch(obj.event){
                case 'delite':
                    layer.open({
                        type: 1,
                        title:'查看历史批注',
                        area: ['700px', '750px'], //自定义文本域宽高
                        content: $('#showView') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                    });
                    $.ajax({
                        type:"post",
                        dataType:"json",
                        url:  webUrl+'/task/commentList',//url
                        contentType: "application/json; charset=utf-8",
                        data:JSON.stringify({'processInstanceId':obj.data.processInstanceId}),
                        success: function (result) {
                            if (result.data.rows.length>0) {
                                var t=result.data.rows;
                                var tbody="";
                                for(var i in t){
                                    var tt=t[i];
                                    var endTime=tt.endTime==null?'':showTime(tt.endTime);

                                    tbody += '<tr><td>' + tt.name + '</td><td>' + showTime(tt.createTime) + '</td>'+
                                        '<td>' + endTime + '</td><td>' + tt.memberName +'</td><td>' + tt.comment +'</td></tr>';
                                }
                                $("#tbody").html(tbody);

                            }
                        },
                        error: function () {
                            layer.msg("操作失败");
                        }

                    })
                    break;
            }
        });

    });

    //时间转换函数
    function showTime(tempDate)
    {
        var d = new Date(tempDate);
        var year = d.getFullYear();
        var month = d.getMonth();
        month++;
        var day = d.getDate();
        var hours = d.getHours();

        var minutes = d.getMinutes();
        var seconds = d.getSeconds();
        month = month<10 ? "0"+month:month;
        day = day<10 ? "0"+day:day;
        hours = hours<10 ? "0"+hours:hours;
        minutes = minutes<10 ? "0"+minutes:minutes;
        seconds = seconds<10 ? "0"+seconds:seconds;


        var time = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
        return time;
    }
</script>

</body>
</html>